<%@ page language="java"  contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>授权角色</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script type="text/javascript" src="${ctx }/extjs/easyext/ux/TreeCheckNodeUI.min.js"></script>
<script language="javascript" type="text/javascript">
var saveCounter=0;

function closeCurrentWindow() {
	var winId='${winId}';
	var closeWin=Ext.WindowMgr.get(winId);
	if(closeWin==null){
		closeWin=parent.Ext.WindowMgr.get(winId);
	}
	if(closeWin==null){
		window.returnValue=(saveCounter>0);
		window.close();
	}else{
		closeWin.returnValue=(saveCounter>0);
		closeWin.close();
	}
}

Ext.onReady(function() {

	var treePanel = new Ext.tree.TreePanel({
		style: 'text-align: left',
		autoScroll: true, // 自动滚动 
		frame: false, // 美化界面 
		enableDD: false,// 是否支持拖拽效果 
		containerScroll: true,// 是否支持滚动条 
		rootVisible: false, // 是否隐藏根节点,很多情况下，我们选择隐藏根节点增加美观性 
		border: false, // 边框
		animate: true, // 动画效果
		//checkModel : "childCascade",
		onlyLeafCheckable: false, //对树所有结点都可选
		bbar: [{
			iconCls: 'acceptBtn',
			text: '保存',
			handler: function() {
				var roleIds=new Array();
				treePanel.root.cascade(function(n) {
					if(n.attributes.checked) {
						roleIds.push(n.id);
					}
				    return true;
				});
				Common.ajaxRequest('${ctx}/user!addRoleJSON.action',{
					id: ${id},
					roleIds: roleIds
				},function(success) {
					if(success) {
						++saveCounter;
						closeCurrentWindow();
					}
				});
			}
		},'-',{
			iconCls: 'delete2Btn',
			text: '取消',
			handler: function() {
				closeCurrentWindow();
			}
		}],
	    root: new Ext.tree.AsyncTreeNode({
			id: '1',
			text: 'ROOT',
			leaf: false,
			expanded: true
	    }),
		loader: new Ext.tree.TreeLoader({
			url: '${ctx}/user!listRoleJSON.action',
			baseAttrs: {
				uiProvider: Ext.ux.TreeCheckNodeUI
			},
			baseParams : {
				id: '${id}'
			}
		})
	});
	
	var viewport = new Ext.Viewport({
		layout: 'fit',
		items: [treePanel]
	});
});
</script>
</head>

<body>
</body>
</html>
